package com.realgodo.site.web.user.music;

import java.util.Date;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.application.music.Music;
import com.realgodo.site.service.application.MusicManager;
import com.realgodo.site.web.user.UserDefaultController;

@Scope("prototype")
@Results({
	@Result(name = IndexController.TO_INDEX, type = "redirect", location = "${base}/user/music/")
})
public class IndexController extends UserDefaultController {

	/***/
	private static final long serialVersionUID = 9097855008767632569L;
	public static final String TO_INDEX="toIndex";
	@Autowired
	private MusicManager musicManager;
	private String url;
	private String name;
	private Page<Music> musicPage;
	
	
	/**进入音乐页*/
	public String execute() throws Exception {
		super.getParamMap().put("spaceId", getSpace().getId().toString());
		musicPage=musicManager.find(PAGE_SIZE,super.getParamMap());
		super.setPageInfo(musicPage);
		return SUCCESS;
	}
	
	public String delete(){
		musicManager.delete(id);
		return TO_INDEX;
	}
	
	public String save(){
		Music music=null;
		if(id!=null){
			music=musicManager.get(id);
		}else{
			music=new Music();
			music.setClasz(Music.class);
			music.setTypeName(Music.TYPE_NAME_MUSIC);
			music.setPubTime(new Date());
			music.setSpace(super.getSpace());
		}
		music.setName(name);
		music.setUrl(url);
		musicManager.save(music);
		return TO_INDEX;
	}

	//--------------set/get-----------//
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Page<Music> getMusicPage() {
		return musicPage;
	}
	
	
}
